Skip to content

feat(pds): Remove bucket_name from R2 Binding - #201

Open
helloimalastair wants to merge 1 commit into
ascorbic:mainfrom
helloimalastair:remove-bucket-name
Open

feat(pds): Remove bucket_name from R2 Binding#201
helloimalastair wants to merge 1 commit into
ascorbic:mainfrom
helloimalastair:remove-bucket-name

Conversation

@helloimalastair

Copy link
Copy Markdown

Closes #107.

When going through the creation flow for a new PDS, wrangler will now auto-create a bucket using wrangler's Automatic Provisioning feature, which should prevent collisions between multiple PDSses, as you cannot have two Workers on an account with the same name.

Example output from the deploy flow:

Experimental: The following bindings need to be provisioned:
Binding           Resource
env.BLOBS         R2 Bucket


Provisioning BLOBS (R2 Bucket)...
🌀 Creating new R2 Bucket "my-pds-pds-blobs"...
✨ BLOBS provisioned 🎉

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've checked this against wrangler's source and the config is valid: bucket_name is optional in the schema, provisioning is on by default and will create <worker>-blobs on first deploy, and both miniflare and the vite plugin handle the absent field. So for fresh scaffolds on current wrangler this works. A few things I want to talk through before merging though.

Blob orphaning on rename / recreate

With an explicit bucket_name, wrangler's provisioning reconnects to an existing bucket regardless of which script it's deploying. Without one, it only inherits bindings already on this script — so a renamed Worker, or one deleted and recreated, silently gets a brand new empty <newname>-blobs and every existing blob 404s. Wrangler mitigates this by writing the provisioned name back into wrangler.jsonc, but only when interactive; CI deploys never get it pinned.

What I'd prefer: keep the template as you have it, and have pds init write bucket_name: "<worker>-blobs" explicitly — it already patches name, routes and account_id via experimental_patchConfig in cli/utils/wrangler.ts, so it's one more field. That gives per-worker uniqueness and a pinned name, and it actually closes #107, which asks for a way to choose the name (this PR changes the default but still doesn't give a choice). Happy for that to be a follow-up if you'd rather keep this one small — but then please change "Closes #107" to "Related to".

Docs now contradict the template

These all still show bucket_name and tell people to pick a unique one:

  • docs/src/content/docs/reference/wrangler-config.md (~L112-120 and L153)
  • docs/src/content/docs/guides/troubleshoot.md ~L135 ("edit wrangler.jsonc" for a taken bucket name)
  • docs/src/content/docs/reference/environment-variables.md ~L103
  • packages/pds/README.md ~L71
  • demos/pds/wrangler.jsonc (not wrong, just no longer mirrors the template)

Small

  • Needs a changeset for create-pds — something like "R2 bucket is now named after the Worker and created on first deploy". Commit scope should be create-pds rather than pds.
  • The old config also auto-created pds-blobs through the same provisioning path; the real behaviour change is the naming, not auto-creation. Worth saying that in the description.
  • Template pins wrangler: ^4.54.0; anyone pinned below the version where provisioning became default-on gets BLOBS bindings must have a "bucket_name" field. Probably worth bumping the floor to something you've verified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: allow customization of cloudflare r2 bucket name

2 participants